package view.items;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import constants.Icons;
import controller.CompleteListener;





public class GrenadePanel extends ItemPanel implements ActionListener {

	private static final String[] grenadeStrings = {"FB", "HE", "SG"};
	
	private JLabel grenadeIcon;
	private JComboBox typeBox;
	
	public GrenadePanel() {
		super();
		
		grenadeIcon = new JLabel(Icons.getIcon("fb"));
		typeBox = new JComboBox(grenadeStrings);
		
		JPanel row1 = new JPanel();
		JPanel row2 = new JPanel();
		
		addButton.setActionCommand("addGre");
		delButton.setActionCommand("delGre");
		
		addButton.setToolTipText("Adds a grenade event");
		delButton.setToolTipText("Removes the selected grenade event");
		
		setAddIcon(Icons.getIcon("addGre"));
		setDelIcon(Icons.getIcon("delGre"));
		
		typeBox.addActionListener(this);
		
		this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
		row1.setLayout(new BoxLayout(row1,BoxLayout.LINE_AXIS));
		row2.setLayout(new BoxLayout(row2,BoxLayout.LINE_AXIS));
		
		this.setBorder(BorderFactory.createTitledBorder("Grenade"));
		row1.setBorder(BorderFactory.createEmptyBorder(0, 0, 3, 0));
		row2.setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0));
		
		row1.add(addButton);
		row1.add(Box.createHorizontalStrut(5));
		row1.add(delButton);
		
		row2.add(typeBox);
		row2.add(Box.createHorizontalStrut(5));
		row2.add(grenadeIcon);
		
		this.add(row1);
		this.add(row2);
		this.add(Box.createVerticalGlue());
		
		typeBox.setMaximumSize(new Dimension(40,20));
		this.setMaximumSize(new Dimension(70,80));
		this.setPreferredSize(new Dimension(70,80));
	}
	
	public int getGreType() {
		return typeBox.getSelectedIndex();
	}
	
	public void setIdle() {
		addButton.setIcon(Icons.getIcon("addGre"));
		delButton.setIcon(Icons.getIcon("delGre"));
	}
	
	public void setAddingGre() {
		addButton.setIcon(Icons.getIcon("addingGre"));
		delButton.setIcon(Icons.getIcon("delGre"));
	}
	
	public void setDeletingGre() {
		addButton.setIcon(Icons.getIcon("addGre"));
		delButton.setIcon(Icons.getIcon("deletingGre"));
	}
	
	@Override
	public void attachListener(CompleteListener l) {
		// TODO Auto-generated method stub
		addButton.addActionListener(l);
		delButton.addActionListener(l);
	}
	
	@Override
	public void setEnabled(boolean enable) {
		addButton.setEnabled(enable);
		delButton.setEnabled(enable);
		typeBox.setEnabled(enable);
	}


	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		switch (typeBox.getSelectedIndex()) {
		case 0:
			grenadeIcon.setIcon(Icons.getIcon("fb"));
			break;
		case 1:
			grenadeIcon.setIcon(Icons.getIcon("he"));
			break;
		case 2:
			grenadeIcon.setIcon(Icons.getIcon("sg"));
			break;
		default:
			break;
		}
	}

}
